package set_;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author wly
 * @version V1.0.0
 * @date 2023/1/10 16:54
 */
public class SetMethod01 {
    public static void main(String[] args) {
        Set set = new HashSet();
        set.add("john");
        set.add("lucy");
        set.add("john");//重复
        set.add("jack");
        set.add("hsp");
        set.add("mary");
        set.add(null);//
        set.add(null);//再次添加null
        for (int i = 0; i < 5; i++) {
            System.out.println("set=" + set);
        }

        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            System.out.println("obj=" + next);
        }

        set.remove(null);

        //方式2: 增强for
        System.out.println("=====增强for====");

        for (Object o : set) {
            System.out.println("o=" + o);
        }
    }
}
